package com.cduestc.animation;

import android.app.Activity;
import android.app.Application;
import android.content.SharedPreferences;

import java.util.LinkedList;
import java.util.List;

public class ExitApp extends Application {
    private List<Activity> list = new LinkedList<Activity>();
    //静态的对象
    private static ExitApp instance;

    private ExitApp(){ }

    //实例化 单例模式
    public synchronized static ExitApp getInstance(){
        if(instance == null){
            instance = new ExitApp();
        }
        return instance;
    }

    public void addActivity(Activity activity){
        list.add(activity);
    }

    //退出
    public void exit(){
        try{
            for(Activity act : list){
                if(act != null){
                    act.finish();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            System.exit(0);
        }
    }

    //关闭进程
    public void onLowMemory() {
        super.onLowMemory();

        //回收垃圾
        System.gc();
    }
}
